package com.lwj.liwanjia.view.activity.logistics;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.adapter.YizhanAdapter;
import com.lwj.liwanjia.base.BaseActivity;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;
import com.superrecycleview.superlibrary.recycleview.SuperRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 附近驿站
 */
public class YizhanActivity extends BaseActivity {

    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rlv_yizhan)
    SuperRecyclerView rlvYizhan;

    private YizhanAdapter adapter;
    private List<String> list = new ArrayList<>();
    private int checkPosition = 0;

    @Override
    protected void initView() {
        tvLeft.setVisibility(View.VISIBLE);
        tvTitle.setText("附近驿站");
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        rlvYizhan.setLayoutManager(manager);
        rlvYizhan.setRefreshEnabled(false);
        rlvYizhan.setLoadMoreEnabled(false);
        adapter = new YizhanAdapter(this, list);
        adapter.setCheckPosition(checkPosition);
        rlvYizhan.setAdapter(adapter);
        listener();
    }

    private void listener() {
        adapter.setOnItemClickListener(new SuperBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, Object item, int position) {
                checkPosition = position;
                adapter.setCheckPosition(position);
                adapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    protected void initData() {
        list.add("1");
        list.add("1");
        list.add("1");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_yizhan;
    }

    @OnClick({R.id.tv_left, R.id.tv_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_left:
                finish();
                break;
            case R.id.tv_sure:
                Intent intent = new Intent();
                //通过checkPosition取值
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }
}
